package com.example.day1203_newsport.proveder;


import com.example.day1203_newsport.ResourceTable;
import ohos.agp.components.*;
import ohos.distributedschedule.interwork.DeviceInfo;

import java.util.List;

public class DeviceProvider extends BaseItemProvider {

    private List<DeviceInfo> deviceInfos;

    public DeviceProvider(List<DeviceInfo> deviceInfos) {
        this.deviceInfos = deviceInfos;
    }

    @Override
    public int getCount() {
        return deviceInfos == null ? 0 : deviceInfos.size();
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public Component getComponent(int position, Component component, ComponentContainer componentContainer) {
        ViewHolder viewHolder;
        Component temp = component;
        if (temp == null) {
            temp = LayoutScatter.getInstance(componentContainer.getContext()).parse(ResourceTable.Layout_item_device, null, false);
            viewHolder = new ViewHolder();
            viewHolder.text = temp.findComponentById(ResourceTable.Id_text);
            temp.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) temp.getTag();
        }

        viewHolder.text.setText(deviceInfos.get(position).getDeviceName());


        return temp;
    }

    private class ViewHolder {
        private Text text;
    }
}
